<%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2022/7/4
  Time: 9:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/style.css"/>
    <script>
        function checkName(t) {
            if(t.value==""){
                alert("课程名没写");
                return false;
            }
            let xhr=new XMLHttpRequest();
            xhr.onreadystatechange=function(){
                if(xhr.readyState==4 &&xhr.status==200){
                    let rtn=xhr.responseText;//out.print
                    if(rtn=="true"){
                        alert("此课程["+t.value+"]已经存在");
                    }else{
                        alert("此课程名可以使用");
                    }
                }
            }
            xhr.open("get","checkSubjectName.do?subjectname="+t.value);
            xhr.send(null);
        }
    </script>
</head>
<body>

<!--主体内容-->
<section class="publicMian ">

    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>课程管理 >> 课程添加</span>
        </div>
        <div class="providerAdd">
            <form action="doAddSubject.jsp" method="post">
                <!--div的class 为error是验证错误，ok是验证成功-->
                <div>
                    <%
                        String msg=(String)request.getAttribute("msg");
                    %>
                    <span style="font-size:40px;color:red;">
                        <%=msg==null?"":msg%>
                    </span>
                </div>
                <div>
                    <label for="subjectname">课程名称：</label>
                    <input type="text" name="subjectname" id="subjectname" onblur="checkName(this)" required/>
                    <span >*请输入课程名称</span>
                </div>
                <div>
                    <label for="classhour">课时：</label>
                    <input type="number" name="classhour" id="classhour" min="1" required/>
                    <span>*请输入商品单位</span>
                </div>


                <div>
                    <label >年级：</label>
                    <select name="gradeid" >
                        <option value="1">高一</option>
                        <option value="2">高二</option>
                    </select>
                    <span>*请选择年级</span>
                </div>

                <div class="providerAddBtn">
                    <!--<a href="#">保存</a>-->
                    <!--<a href="billList.html">返回</a>-->
                    <input type="submit" value="保存" />
                    <input type="button" value="返回" onclick="history.back(-1)"/>
                </div>
            </form>
        </div>

    </div>
</section>

</body>
</html>
